<template>
  <div>
      <el-form ref="editTypeForm" :rules="rules" :model="editTypeForm" label-width="80px">
        <el-form-item label="分类名称" prop="name">
          <el-input v-model="editTypeForm.name"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm('editTypeForm')">确认修改</el-button>
        <el-button @click="resetForm">取消</el-button>
      </span>
  </div>
</template>

<script>
  export default {
    name: "EditShopType",
    data() {
      return {
        editTypeForm: {id:0,name:""},
        dialogVisible: false,//模态框状态
        rules: {
          name: [
            {required: true, message: '请输入分类名称', trigger: 'blur'}
          ]
        }
      }
    },
    methods: {
      getdata(id){
        //打开编辑
        this.$axios
          .get("shopType/shopType.action/" + id)
          .then((res) => {
            this.$nextTick(item=>{
              this.editTypeForm.id=res.data.id;
              this.editTypeForm.name=res.data.name;
            });
          })
          .catch(err => {
            this.$message.error(err)
          })
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$axios
              .put("shopType/shopType.action",this.editTypeForm)
              .then(res => {
                if (res.data.code>0){
                  this.$parent.$parent.dialogVisible=false;
                  this.$parent.$parent.getTypes();
                  this.$message.success(res.data.msg);
                }else {
                  this.$message.error(res.data.msg);
                }
              })
              .catch(err => {
                this.$message.error(err)
              })
          } else {
            this.$message.error('error submit!!');
            return false;
          }
        });
      },
      resetForm() {
        this.editForm = {};
        this.$parent.$parent.dialogVisible = false;
      }

    }
  }
</script>

<style scoped>

</style>
